package com.yanqu.road.logic.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yanqu.road.queue.LogAnalysisReceiveQueue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author duli
 * @version 1.0
 * @date 2020/9/9 14:08
 * @Description
 */
@Controller
@RequestMapping("/logAnalysis")
public class LogAnalysisController {
    private final static Logger log = LoggerFactory.getLogger(LogAnalysisController.class);

    @RequestMapping("/batch")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public JSONObject batch(@RequestBody JSONObject obj){
        JSONObject jsonObject = new JSONObject();
        try {
            JSONArray jsonArray= obj.getJSONArray("data");
            jsonArray.stream().forEach(object->{
                LogAnalysisReceiveQueue.add(object);
            });
            jsonObject.put("state", "0");
            jsonObject.put("msg","成功");
        }catch (Exception e){
            log.error("logAnalysis receive faild;reason is "+e.getMessage());
            jsonObject.put("state", "500");
            jsonObject.put("msg","系统错误");
        }
        return jsonObject;
    }

}
